import subprocess as sb
import os

def excute(proc, cmd):
    proc.stdin.write(cmd)

def log(proc):
    for line in iter(proc.stdout.readline, b''):
        print(str(line, encoding="utf-8"), end="")


proc = sb.Popen([".\\db.exe", "user.db"] , stdin=sb.PIPE, stdout=sb.PIPE,
    stderr=sb.PIPE)

for id in range(1, 13):
    cmd = "insert " + str(id) + " yang 123@qq.com\n";
    print(cmd)
    excute(proc=proc, cmd=bytes(cmd, encoding="utf-8"))
excute(proc=proc, cmd=b"btree\n")
excute(proc=proc, cmd=b".exit\n")

proc.stdin.flush()

log(proc)
proc.kill()
